import { Button, Form, Input } from 'antd';
import { PlusCircleOutlined, DeleteOutlined } from '@ant-design/icons';

export const UpdateTableColumns = (onTableClick, enterType) => {
  return [
    {
      title: '序号',
      dataIndex: 'index',
      key: 'index',
      width: 80,
      visible: true,
      render: (text, record, index) => {
        return <div>{index + 1}</div>;
      },
    },
    {
      title: '联系人姓名',
      dataIndex: 'fullName',
      key: 'fullName',
      width: 200,
      visible: true,
      render: (text, record, index) => {
        return (
          <>
            <Form.Item
              name={['table', index, 'fullName']}
              rules={
                enterType
                  ? undefined
                  : [
                      {
                        required: true,
                        message: '请输入联系人姓名',
                      },
                    ]
              }
            >
              <Input placeholder="请输入" />
            </Form.Item>
          </>
        );
      },
    },
    {
      title: '联系人电话',
      daatIndex: 'phoneMobile',
      key: 'phoneMobile',
      width: 200,
      visible: true,
      render: (text, record, index) => {
        return (
          <>
            <Form.Item
              name={['table', index, 'phoneMobile']}
              rules={
                enterType
                  ? undefined
                  : [
                      {
                        required: true,
                        message: '请输入联系人电话',
                      },
                    ]
              }
            >
              <Input placeholder="请输入" />
            </Form.Item>
          </>
        );
      },
    },
    {
      title: (
        <div style={{ textAlign: 'center' }}>
          <Button type="link" icon={<PlusCircleOutlined />} onClick={() => onTableClick('add')}>
            添加
          </Button>
        </div>
      ),
      dataIndex: 'operation',
      key: 'operation',
      width: 80,
      visible: true,
      render: (text, record, index) => {
        if (index === 0) {
          return <div style={{ textAlign: 'center' }}>--</div>;
        }
        return (
          <div style={{ textAlign: 'center' }}>
            <Button danger type="link" icon={<DeleteOutlined />} className="manageColorRedBtn" onClick={() => onTableClick('delete', index)}>
              删除
            </Button>
          </div>
        );
      },
    },
  ];
};
